using MicroMsg.Common.Utils;
using MicroMsg.Manager;
using MicroMsg.Plugin.FaceBook;
using MicroMsg.Plugin.Sns.Scene;
using MicroMsg.Resource.@string;
using MicroMsg.Storage;
using MicroMsg.UI.ImageFilter;
using MicroMsg.UI.UserContrl;
using MicroMsg.UI.Util;
using Microsoft.Phone.Controls;
using Microsoft.Phone.Controls.Primitives;
using Microsoft.Phone.Shell;
using Microsoft.Xna.Framework.Media;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Device.Location;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Xml.Linq;
namespace MicroMsg.UI.Page
{
	public class SnsPostPage : BasePage
	{
		private enum InputMode
		{
			InputTxtMode,
			InputSmileyMode,
			NoneMode
		}
		private const string TAG = "SnsPostPage";
		private bool bTapFromChildren;
		private bool isFromShareContent;
		private string strShareContentToken;
		public List<Contact> conList = new List<Contact>();
		public List<TloMedia> picPathList = new List<TloMedia>();
		private bool bIsFirstLoad = true;
		private double mLatitude;
		private double mLongitude;
		private string mAddress = "";
		private SnsPostPage.InputMode nowMode = SnsPostPage.InputMode.NoneMode;
		private SnsPostImageContainer addPictureButton;
		private SnsPostImageContainer delPictureButton;
		private bool bIfGetLocation = true;
		private bool bIfSyncToTencentWeibo;
		private bool bIfSyncToFB;
		private bool bIfSetPrivate;
		private bool isDeleteState;
		private ApplicationBar mBar;
		private ApplicationBarIconButton OkMenuBtn;
		private ApplicationBarIconButton smelyBtn;
		private bool hasCoverInfront;
		private List<ulong> mListSnsGroupId;
		internal Grid LayoutRoot;
		internal ScrollViewer rootScrollViewer;
		internal StackPanel LayoutContent;
		internal TextBlock InfoText;
		internal ChatInputTextBox InputTextBox;
		internal WrapPanel ImagePanel;
		internal ClickableLayout btnVisibility;
		internal StackPanel panelVisibility;
		internal Image imgVisi;
		internal TextBlock txtVisiLead;
		internal DynamicTextBlock txtVisiKind;
		internal ClickableLayout btnCommonSetting;
		internal StackPanel WithPanel;
		internal TextBlock WithText;
		internal TextBlock remindNumber;
		internal Image LocatonImg;
		internal TextBlock LocatonTxt;
		internal ToggleSwitchButton LocationToggle;
		internal StackPanel SyncToWeiboGrid;
		internal Image SyncToWeiboImg;
		internal TextBlock SyncToWeiboTxt;
		internal ToggleSwitchButton ShareToTencentWeiboToggle;
		internal StackPanel SyncToFBGrid;
		internal Image SyncToFBImg;
		internal TextBlock SyncToFBTxt;
		internal ToggleSwitchButton SyncToFBToggle;
		internal Image PrivacyImg;
		internal TextBlock PrivacyTxt;
		internal TextBlock PrivacyTipTxt;
		internal ToggleSwitchButton SetPrivacyToggle;
		internal PerformanceProgressBar NetStatusProgressBar;
		internal SmileyOverlay SmileyView;
		private bool _contentLoaded;
		public SnsPostPage()
		{
			List<ulong> list = new List<ulong>();
			list.Add(1uL);
			this.mListSnsGroupId = list;
			base..ctor();
			this.InitializeComponent();
			base.add_Loaded(new RoutedEventHandler(this.SnsPostPage_Loaded));
			this.InitTakingPhotoes();
		}
		protected override void OnPageIn(object[] object_0)
		{
			if (object_0 != null && object_0.Length > 0 && object_0[0] != null)
			{
				if (object_0[0] is Stream)
				{
					Stream resultData = null;
					if (object_0[0] != null)
					{
						resultData = (object_0[0] as Stream);
					}
					this.addSinglePicture(resultData);
				}
				else
				{
					if (object_0[0] is string)
					{
						this.isFromShareContent = true;
						this.strShareContentToken = (object_0[0] as string);
						this.InitAlbumPhoto(this.strShareContentToken);
					}
					else
					{
						if (object_0[0] is MultiPhotoChooserResult)
						{
							MultiPhotoChooserResult multiPhotoChooserResult = object_0[0] as MultiPhotoChooserResult;
							if (multiPhotoChooserResult.Pictures != null)
							{
								this.addMultiPictures(multiPhotoChooserResult.Pictures);
							}
							else
							{
								if (multiPhotoChooserResult.SingleResult != null)
								{
									this.addSinglePicture(multiPhotoChooserResult.SingleResult.Image);
								}
							}
						}
					}
				}
				if (this.bIsFirstLoad)
				{
					this.bIsFirstLoad = false;
					this.InitUIResource();
					this.InitSmiley();
					this.LayoutRoot.add_Tap(new EventHandler<GestureEventArgs>(this.LayoutRoot_Tap));
				}
			}
			base.set_ApplicationBar(this.GetApplicationBar());
			this.txtVisiKind.Text = this.getDisplayVisiText();
		}
		private void InitAlbumPhoto(string strPicToken)
		{
			MediaLibrary mediaLibrary = new MediaLibrary();
			Picture pictureFromToken = mediaLibrary.GetPictureFromToken(strPicToken);
			Stream image = pictureFromToken.GetImage();
			image.Seek(0L, 0);
			byte[] array = new byte[image.get_Length()];
			image.Read(array, 0, array.Length);
			image.Seek(0L, 0);
			this.addSinglePicture(image);
		}
		private void SnsPostPage_Loaded(object sender, RoutedEventArgs e)
		{
			if (this.bIsFirstLoad)
			{
				this.InitUIResource();
				this.InitSmiley();
				this.LayoutRoot.add_Tap(new EventHandler<GestureEventArgs>(this.LayoutRoot_Tap));
				this.bIsFirstLoad = false;
			}
			this.InputTextBox.add_Tap(new EventHandler<GestureEventArgs>(this.InputTextBox_Tap));
			this.InputTextBox.add_GotFocus(new RoutedEventHandler(this.InputTextBox_GotFocus));
			this.InputTextBox.add_LostFocus(new RoutedEventHandler(this.InputTextBox_LostFocus));
			if (this.InputTextBox.realBox != null)
			{
				this.InputTextBox.realBox.add_TextChanged(new TextChangedEventHandler(this.realBox_TextChanged));
			}
			this.getGeoAddressAsync();
			if (this.mBar != null)
			{
				this.mBar.set_IsVisible(true);
			}
		}
		private void realBox_TextChanged(object sender, TextChangedEventArgs e)
		{
			this.GetTextState();
		}
		private void InputTextBox_Tap(object sender, GestureEventArgs e)
		{
			this.bTapFromChildren = true;
		}
		private void LayoutRoot_Tap(object sender, GestureEventArgs e)
		{
			if (this.bTapFromChildren)
			{
				this.bTapFromChildren = false;
				return;
			}
			this.SwitchToMode(SnsPostPage.InputMode.NoneMode);
		}
		private void getGeoAddressAsync()
		{
			if (this.mAddress != null && this.mAddress.get_Length() > 0)
			{
				return;
			}
			GeoCoordinateWatcher geoCoordinateWatcher = new GeoCoordinateWatcher(1);
			geoCoordinateWatcher.set_MovementThreshold(1.0);
			if (geoCoordinateWatcher.TryStart(false, TimeSpan.FromMilliseconds(1000.0)))
			{
				this.mLatitude = geoCoordinateWatcher.get_Position().get_Location().get_Latitude();
				this.mLongitude = geoCoordinateWatcher.get_Position().get_Location().get_Longitude();
				this.accessGoogleAPI(this.mLatitude, this.mLongitude);
			}
		}
		private void accessGoogleAPI(double paramLatitude, double paramLongitude)
		{
			Log.smethod_5("SnsPostPage", "Begin GetData");
			string text = paramLatitude + "," + paramLongitude;
			string text2 = "&language=zh-CN&sensor=false";
			string text3 = "&language=en&sensor=false";
			string text4 = "&language=zh-TW&sensor=false";
			string text5;
			if (R.isChineseCN())
			{
				text5 = text2;
			}
			else
			{
				if (R.isChineseTW())
				{
					text5 = text4;
				}
				else
				{
					text5 = text3;
				}
			}
			HttpWebRequest request = (HttpWebRequest)WebRequest.Create("http://maps.google.com/maps/api/geocode/xml?latlng=" + text + text5);
			request.BeginGetResponse(delegate(IAsyncResult asyncResult)
			{
				try
				{
					HttpWebResponse httpWebResponse = (HttpWebResponse)request.EndGetResponse(asyncResult);
					XDocument xDocument = XDocument.Load(httpWebResponse.GetResponseStream());
					XElement xElement = xDocument.Element("GeocodeResponse");
					if (xElement != null)
					{
						Log.smethod_4("SnsPostPage", "GeocodeResponse is a xml");
						XElement xElement2 = xElement.Element("status");
						if (xElement2 != null)
						{
							string value = xElement2.get_Value();
							if (value.Equals("OK"))
							{
								Log.smethod_4("SnsPostPage", "request position info get right response!");
								using (IEnumerator<XElement> enumerator = xElement.Elements().GetEnumerator())
								{
									while (enumerator.MoveNext())
									{
										XElement current = enumerator.get_Current();
										XElement xElement3 = current.Element("type");
										if (xElement3 != null)
										{
											using (IEnumerator<XElement> enumerator2 = current.Elements().GetEnumerator())
											{
												while (enumerator2.MoveNext())
												{
													XElement current2 = enumerator2.get_Current();
													if (current2.get_Name() == "address_component")
													{
														XElement xElement4 = current2.Element("type");
														if (xElement4 != null && xElement4.get_Value() == "locality")
														{
															XElement xElement5 = current2.Element("long_name");
															this.mAddress = xElement5.get_Value();
															if (this.mAddress != null && this.mAddress.get_Length() > 0)
															{
																this.get_Dispatcher().BeginInvoke(delegate
																{
																	this.LocatonTxt.set_Text(this.mAddress);
																});
															}
															return;
														}
													}
												}
											}
										}
									}
								}
							}
						}
					}
					this.mAddress = "";
				}
				catch (Exception ex)
				{
					this.mAddress = "";
					Log.smethod_1("SnsPostPage", ex.ToString());
				}
			}, null);
		}
		private List<string> getCurNames()
		{
			List<string> list = new List<string>();
			using (List<Contact>.Enumerator enumerator = this.conList.GetEnumerator())
			{
				while (enumerator.MoveNext())
				{
					Contact current = enumerator.get_Current();
					if (current != null)
					{
						list.Add(current.strUsrName);
					}
				}
			}
			return list;
		}
		private void getContactListCallback(object obj1, object obj2)
		{
			if (obj2 == null)
			{
				return;
			}
			List<Contact> argList = obj2 as List<Contact>;
			this.GetContactListName(argList);
		}
		private void WithPanel_Tap(object sender, RoutedEventArgs e)
		{
			if (this.isSetPrivate())
			{
				MMMessageBox.Show(strings.Ablum_Cannot_Set_Remind_Warning, true, "确定");
				return;
			}
			this.ResetAllPic();
			new ContactCheckDone(this.GetContactListName);
			if (this.conList != null && Enumerable.Count<Contact>(this.conList) != 0)
			{
				object[] para = new object[]
				{
					this.conList,
					new RemindAttentionPage.ContactChooseCompelete(this.RemindChooseCompelete)
				};
				RemindAttentionPage.GoToThisPage(para);
				return;
			}
			AddContactsPage.GotoThisPage(new AddContactsPageArgs
			{
				mDlgGetContacts = new MMStandardUIEvent(this.getContactListCallback),
				mType = ContactsViewType.CONTACT_VIEW_CHECKTOADD,
				mNFilterKind = 6,
				mListFilter = this.getCurNames()
			});
		}
		private void postPhotoConCtrl_AddClick(object sender, object object_0)
		{
			this.ResetAllPic();
			object[] object_ = new object[]
			{
				ChoosePeoplePage.ChoosePeoplePageFrom.SnsSharePhoto,
				new ContactCheckDone(this.GetContactListName),
				this.conList
			};
			base.GoToPage("/Source/Plugin/MassSend/UI/ChoosePeoplePage.xaml", object_, false);
		}
		private void RemindChooseCompelete(List<Contact> contactList)
		{
			this.conList = contactList;
			this.refreshRemindNumber();
		}
		private void GetContactListName(List<Contact> argList)
		{
			BasePage prevPage = PageManager.getInstance().GetPrevPage();
			if (prevPage != this)
			{
				PageManager.getInstance().PopPage();
			}
			this.conList.AddRange(argList);
			this.refreshRemindNumber();
		}
		private void SwitchToMode(SnsPostPage.InputMode mode)
		{
			if (mode == SnsPostPage.InputMode.InputSmileyMode)
			{
				base.Focus();
				base.get_Dispatcher().BeginInvoke(delegate
				{
					this.SmileyView.set_Visibility(0);
				});
				this.nowMode = SnsPostPage.InputMode.InputSmileyMode;
			}
			else
			{
				if (mode == SnsPostPage.InputMode.InputTxtMode)
				{
					this.SmileyView.set_Visibility(1);
					this.nowMode = SnsPostPage.InputMode.InputTxtMode;
				}
				else
				{
					if (mode == SnsPostPage.InputMode.NoneMode)
					{
						this.SmileyView.set_Visibility(1);
						base.Focus();
						this.ResetAllPic();
						this.nowMode = SnsPostPage.InputMode.NoneMode;
					}
				}
			}
			this.RefreshAppBar();
		}
		protected override void OnBackKeyPress(CancelEventArgs cancelEventArgs_0)
		{
			if (this.nowMode == SnsPostPage.InputMode.InputSmileyMode)
			{
				this.SwitchToMode(SnsPostPage.InputMode.NoneMode);
				cancelEventArgs_0.set_Cancel(true);
			}
		}
		private void InitTakingPhotoes()
		{
			this.addPictureButton = new SnsPostImageContainer();
			this.addPictureButton.SetSource(new ImageSourceConverter().ConvertFromString(R.theme.sns_sendpic_addpeople_icon) as ImageSource);
			this.addPictureButton.ItemClick += new SnsPostImageContainer.SnsPostImageContainer_Click(this.imgContainer_Click);
			this.ImagePanel.get_Children().Add(this.addPictureButton);
			this.delPictureButton = new SnsPostImageContainer();
			this.delPictureButton.SetSource(new ImageSourceConverter().ConvertFromString(R.theme.sns_sendpic_delpeople_icon) as ImageSource);
			this.delPictureButton.ItemClick += new SnsPostImageContainer.SnsPostImageContainer_Click(this.imgContainer_Click);
			this.ImagePanel.get_Children().Add(this.delPictureButton);
		}
		private void refreshRemindNumber()
		{
			int num = (this.conList == null) ? 0 : Enumerable.Count<Contact>(this.conList);
			if (num > 0)
			{
				string text = string.Format("({0})", num);
				this.remindNumber.set_Text(text);
				this.remindNumber.set_Visibility(0);
				return;
			}
			this.remindNumber.set_Visibility(1);
		}
		private void InitUIResource()
		{
			this.LayoutRoot.set_Background(R.theme.SNS_MAINPAGE_BK_BRUSH);
			this.InfoText.set_Text(strings.Album_TakingPhoto_Info);
			this.InputTextBox.HintText = strings.Album_AddPhotoTitle;
			this.InputTextBox.set_VerticalContentAlignment(0);
			this.imgVisi.set_Source(new ImageSourceConverter().ConvertFromString(R.theme.Sns_ImgPath_syncToPeople) as ImageSource);
			this.WithText.set_Text(strings.Album_Remind_Friend);
			this.refreshRemindNumber();
			this.LocatonImg.set_Source(new ImageSourceConverter().ConvertFromString(R.theme.Sns_ImgPath_getLocaton) as ImageSource);
			this.LocatonTxt.set_Text(strings.Album_GettingLocation);
			if (AccountMgr.getCurAccount().nBindQQ != 0u)
			{
				this.SyncToWeiboImg.set_Source(new ImageSourceConverter().ConvertFromString(R.theme.Sns_ImgPath_syncToTencentWeibo) as ImageSource);
				this.SyncToWeiboTxt.set_Text(strings.Reader_Share_To_Weibo_Title);
				this.SyncToWeiboGrid.set_Visibility(0);
			}
			else
			{
				this.SyncToWeiboGrid.set_Visibility(1);
			}
			if (AccountMgr.getCurAccount().FBUserID != 0uL && !FaceBookMgr.IsChina())
			{
				this.SyncToFBImg.set_Source(new ImageSourceConverter().ConvertFromString(R.theme.Sns_ImgPath_syncToFaceBook) as ImageSource);
				this.SyncToFBTxt.set_Text(strings.Album_Write_Facebook);
				this.SyncToFBGrid.set_Visibility(0);
			}
			else
			{
				this.SyncToFBGrid.set_Visibility(1);
			}
			this.PrivacyImg.set_Source(new ImageSourceConverter().ConvertFromString(R.theme.Sns_ImgPath_setPrivate) as ImageSource);
			this.PrivacyTxt.set_Text(strings.Album_Write_Secret);
			this.PrivacyTipTxt.set_Text(strings.WC_Commit_secret_tips);
			this.PrivacyTipTxt.set_Visibility(1);
		}
		private void checkedOn(object sender, RoutedEventArgs e)
		{
			if (sender == this.LocationToggle)
			{
				this.bIfGetLocation = true;
				this.getGeoAddressAsync();
				return;
			}
			if (sender == this.ShareToTencentWeiboToggle)
			{
				if (this.isSetPrivate())
				{
					this.ShareToTencentWeiboToggle.set_IsChecked(new bool?(false));
					MessageBoxManager.ShowToast(strings.Setting_Conflict_Privacy, 2500, null, false);
					return;
				}
				if (!AccountMgr.hasTWeibo())
				{
					this.ShareToTencentWeiboToggle.set_IsChecked(new bool?(false));
					MessageBoxManager.ShowToast(strings.Setting_NoTentcentWeibo, 2500, null, false);
					return;
				}
				this.bIfSyncToTencentWeibo = true;
				if (this.bIfSetPrivate)
				{
					this.bIfSetPrivate = false;
					this.SetPrivacyToggle.set_IsChecked(new bool?(false));
					return;
				}
			}
			else
			{
				if (sender == this.SyncToFBToggle)
				{
					if (this.isSetPrivate())
					{
						this.SyncToFBToggle.set_IsChecked(new bool?(false));
						MessageBoxManager.ShowToast(strings.Setting_Conflict_Privacy, 2500, null, false);
						return;
					}
					this.bIfSyncToFB = true;
					if (this.bIfSetPrivate)
					{
						this.bIfSetPrivate = false;
						this.SetPrivacyToggle.set_IsChecked(new bool?(false));
						return;
					}
				}
				else
				{
					if (sender == this.SetPrivacyToggle)
					{
						this.bIfSetPrivate = true;
						this.PrivacyTipTxt.set_Visibility(0);
						if (this.bIfSyncToTencentWeibo)
						{
							this.bIfSyncToTencentWeibo = false;
							this.ShareToTencentWeiboToggle.set_IsChecked(new bool?(false));
						}
						if (this.bIfSyncToFB)
						{
							this.bIfSyncToFB = false;
							this.SyncToFBToggle.set_IsChecked(new bool?(false));
						}
					}
				}
			}
		}
		private void checkedOff(object sender, RoutedEventArgs e)
		{
			if (sender == this.LocationToggle)
			{
				this.bIfGetLocation = false;
				return;
			}
			if (sender == this.ShareToTencentWeiboToggle)
			{
				this.bIfSyncToTencentWeibo = false;
				return;
			}
			if (sender == this.SyncToFBToggle)
			{
				this.bIfSyncToFB = false;
				return;
			}
			if (sender == this.SetPrivacyToggle)
			{
				this.bIfSetPrivate = false;
				this.PrivacyTipTxt.set_Visibility(1);
			}
		}
		private void ImgScrollViewer_Tap(object sender, GestureEventArgs e)
		{
			this.bTapFromChildren = true;
			if (e.get_OriginalSource() is WrapPanel && this.isDeleteState)
			{
				this.SwitchToMode(SnsPostPage.InputMode.NoneMode);
			}
		}
		public void SelectPicDlgReturn(DlgReturnEventArg dlgReturnEventArg_0)
		{
			switch (MMMessageBox.GetUserClickResult(dlgReturnEventArg_0))
			{
			case 0:
				this.TakePhoto();
				return;
			case 1:
				this.ChooserPicture();
				return;
			default:
				return;
			}
		}
		private void ChooserPicture()
		{
			this.mBar.set_IsVisible(false);
			MultiPhotoChooser.GoToThisPage(new MultiPhotoChooserConfig
			{
				MultiPhotoChooserCallBack = new MultiPhotoChooserCallBack(this.MultiPhotoChooserTaskCompleted),
				IsNeedRotate = true,
				CountLimit = 9 - this.picPathList.get_Count()
			}, false);
		}
		private void TakePhoto()
		{
			this.mBar.set_IsVisible(false);
			ToolFunction.GotoPageForUserControl("/Source/UI/ImageFilter/ImageFilterPage.xaml", new object[]
			{
				new ImageFilterConfig(new ImageFilterCallBack(this.photoCameraCapture_Completed), ImageFilterGetPicMode.GetPicMode_Choose_With_Take, 0, 0, null)
				{
					GetPicMode = ImageFilterGetPicMode.GetPicMode_Take_Photo,
					isSaveToAlbum = ImageFilterMgr.IsSettingAutoSavePhotos()
				}
			}, false);
		}
		private void photoCameraCapture_Completed(Stream resultData)
		{
			if (resultData != null)
			{
				this.addSinglePicture(resultData);
			}
		}
		private void PhotoChooserTaskCompleted(Stream resultData)
		{
			if (resultData != null)
			{
				Log.smethod_5("SnsPostPage", "PhotoChooserTaskCompleted");
				resultData.set_Position(0L);
				byte[] array = new byte[100];
				resultData.Read(array, 0, 100);
				ImageFromat imageFormat = ImageUtil.getImageFormat(array);
				resultData.set_Position(0L);
				Log.smethod_5("SnsPostPage", "image format = " + imageFormat.ToString());
				if (imageFormat != ImageFromat.jpeg)
				{
					if (imageFormat != ImageFromat.const_2)
					{
						Log.smethod_1("SnsPostPage", "send gif image is not supported");
						MMMessageBox.Show(strings.ChatImgSendFormatError, true, "确定");
						return;
					}
				}
				this.addSinglePicture(resultData);
				return;
			}
		}
		private void MultiPhotoChooserTaskCompleted(MultiPhotoChooserResult resultData)
		{
			if (resultData == null)
			{
				return;
			}
			if (resultData.Pictures != null)
			{
				Log.smethod_5("SnsPostPage", "MultiPhotoChooserTaskCompleted");
				this.addMultiPictures(resultData.Pictures);
				return;
			}
			if (resultData.SingleResult != null)
			{
				this.addSinglePicture(resultData.SingleResult.Image);
			}
		}
		private void addSinglePicture(Stream resultData)
		{
			TloMedia tloMedia = SnsPostService.snsSavePhoto(resultData, true, true);
			resultData.Close();
			if (tloMedia == null)
			{
				return;
			}
			tloMedia.nAngle = 0;
			tloMedia.mPicture = null;
			this.picPathList.Add(tloMedia);
			SnsPostImageContainer snsPostImageContainer = new SnsPostImageContainer();
			snsPostImageContainer.SetSource(ImageCacheMgr.loadFromFile(tloMedia.strThumb));
			snsPostImageContainer.ItemClick += new SnsPostImageContainer.SnsPostImageContainer_Click(this.imgContainer_Click);
			int num = 0;
			if (this.ImagePanel.get_Children().Contains(this.addPictureButton))
			{
				num++;
			}
			if (this.ImagePanel.get_Children().Contains(this.delPictureButton))
			{
				num++;
			}
			this.ImagePanel.get_Children().Insert(this.ImagePanel.get_Children().get_Count() - num, snsPostImageContainer);
			if (this.OkMenuBtn != null && !this.OkMenuBtn.get_IsEnabled())
			{
				this.OkMenuBtn.set_IsEnabled(true);
			}
			this.ResetAllPic();
		}
		private void addMultiPictures(List<Picture> pictures)
		{
			int num = 0;
			if (this.ImagePanel.get_Children().Contains(this.addPictureButton))
			{
				num++;
			}
			if (this.ImagePanel.get_Children().Contains(this.delPictureButton))
			{
				num++;
			}
			using (List<Picture>.Enumerator enumerator = pictures.GetEnumerator())
			{
				while (enumerator.MoveNext())
				{
					Picture current = enumerator.get_Current();
					Log.smethod_5("SnsPostPage", "pic save begin");
					TloMedia tloMedia = SnsPostService.snsSaveSysPictureThumb(current.GetThumbnail(), true);
					if (tloMedia == null)
					{
						return;
					}
					tloMedia.mPicture = current;
					tloMedia.nAngle = 0;
					this.picPathList.Add(tloMedia);
					SnsPostImageContainer snsPostImageContainer = new SnsPostImageContainer();
					BitmapImage bitmapImage = new BitmapImage();
					bitmapImage.SetSource(current.GetThumbnail());
					snsPostImageContainer.SetSource(bitmapImage);
					snsPostImageContainer.ItemClick += new SnsPostImageContainer.SnsPostImageContainer_Click(this.imgContainer_Click);
					this.ImagePanel.get_Children().Insert(this.ImagePanel.get_Children().get_Count() - num, snsPostImageContainer);
					if (this.OkMenuBtn != null && !this.OkMenuBtn.get_IsEnabled())
					{
						this.OkMenuBtn.set_IsEnabled(true);
					}
					Log.smethod_5("SnsPostPage", "pic save end");
				}
			}
			this.ResetAllPic();
		}
		private void imgContainer_Click(object sender, object object_0)
		{
			SnsPostImageContainer snsPostImageContainer = sender as SnsPostImageContainer;
			if (snsPostImageContainer == this.addPictureButton)
			{
				MMMessageBox mMMessageBox = MMMessageBox.Show(strings.ChatSendPicDlgTitle, strings.ChatSendPicDlgInfo, true, strings.ChatSendPicDlgTakePhoto, strings.ChatSendPicDlgImgLib);
				mMMessageBox.ReturnEvent = new DlgReturnEvent(this.SelectPicDlgReturn);
				return;
			}
			if (snsPostImageContainer == this.delPictureButton)
			{
				this.turnDeleteMode();
				return;
			}
			int num = this.ImagePanel.get_Children().IndexOf(snsPostImageContainer);
			if (num < 0)
			{
				return;
			}
			if (snsPostImageContainer.IsDeleteState())
			{
				this.DelSnsMediaInUI(num);
				return;
			}
			base.GoToPage("/Source/Plugin/Sns/Common/UI/UploadAndPost/SnsPostSlidePreView.xaml", new object[]
			{
				num,
				new SnsPostSlidePreView.RotateImgEvent(this.RotateThumbImg)
			}, false);
		}
		public void DelSnsMediaInUI(int index)
		{
			if (index >= 0 && index < this.picPathList.get_Count())
			{
				this.ImagePanel.get_Children().RemoveAt(index);
				this.picPathList.RemoveAt(index);
				if (this.picPathList.get_Count() == 0)
				{
					this.OkMenuBtn.set_IsEnabled(false);
					this.ResetAllPic();
				}
				return;
			}
			Log.smethod_1("SnsPostPage", "index = " + index + " out of range!");
		}
		private void RotateThumbImg(List<int> nAngleList)
		{
			for (int i = 0; i < this.picPathList.get_Count(); i++)
			{
				int num = (nAngleList.get_Item(i) + 360 - this.picPathList.get_Item(i).nAngle) % 360;
				if (num != 0)
				{
					SnsPostService.snsRotateThumb(this.picPathList.get_Item(i), num);
					this.picPathList.get_Item(i).nAngle = nAngleList.get_Item(i);
					if (this.ImagePanel.get_Children().get_Item(i) is SnsPostImageContainer)
					{
						(this.ImagePanel.get_Children().get_Item(i) as SnsPostImageContainer).SetSource(ImageCacheMgr.loadFromFile(this.picPathList.get_Item(i).strThumb));
					}
				}
			}
		}
		private void turnDeleteMode()
		{
			this.isDeleteState = true;
			using (IEnumerator<UIElement> enumerator = this.ImagePanel.get_Children().GetEnumerator())
			{
				while (enumerator.MoveNext())
				{
					UIElement current = enumerator.get_Current();
					if (current != this.addPictureButton)
					{
						if (current != this.delPictureButton)
						{
							SnsPostImageContainer snsPostImageContainer = current as SnsPostImageContainer;
							if (snsPostImageContainer != null)
							{
								snsPostImageContainer.SetDeleteState(true);
								continue;
							}
							continue;
						}
					}
					current.set_Visibility(1);
				}
			}
		}
		private void ResetAllPic()
		{
			if (this.isDeleteState)
			{
				this.isDeleteState = false;
				using (IEnumerator<UIElement> enumerator = this.ImagePanel.get_Children().GetEnumerator())
				{
					while (enumerator.MoveNext())
					{
						UIElement current = enumerator.get_Current();
						SnsPostImageContainer snsPostImageContainer = current as SnsPostImageContainer;
						if (snsPostImageContainer != null)
						{
							snsPostImageContainer.SetDeleteState(false);
						}
					}
				}
			}
			if (this.ImagePanel.get_Children().get_Count() < 11)
			{
				if (this.addPictureButton != null)
				{
					this.addPictureButton.set_Visibility(0);
				}
			}
			else
			{
				if (this.addPictureButton != null)
				{
					this.addPictureButton.set_Visibility(1);
				}
			}
			if (this.ImagePanel.get_Children().get_Count() > 2)
			{
				if (this.delPictureButton != null)
				{
					this.delPictureButton.set_Visibility(0);
					return;
				}
			}
			else
			{
				if (this.delPictureButton != null)
				{
					this.delPictureButton.set_Visibility(1);
				}
			}
		}
		private ApplicationBar GetApplicationBar()
		{
			if (this.mBar != null)
			{
				return this.mBar;
			}
			this.mBar = new ApplicationBar();
			this.mBar.set_IsMenuEnabled(true);
			this.mBar.set_IsVisible(true);
			this.mBar.set_Opacity(0.99);
			if (this.mBar != null)
			{
				this.mBar.set_BackgroundColor(((SolidColorBrush)R.theme.COMMON_APPBAR_BK_BRUSH).get_Color());
				this.mBar.set_ForegroundColor(((SolidColorBrush)R.theme.COMMON_APPBAR_FG_BRUSH).get_Color());
			}
			this.OkMenuBtn = new ApplicationBarIconButton(new Uri("/icons/appbar.check.rest.png", 2));
			this.OkMenuBtn.set_Text(strings.COM_Confirm);
			this.OkMenuBtn.add_Click(new EventHandler(this.OkMenuBtn_Click));
			this.mBar.get_Buttons().Add(this.OkMenuBtn);
			this.smelyBtn = new ApplicationBarIconButton(new Uri("/icons/appbar.check.rest.png", 2));
			this.smelyBtn.set_Text(strings.Album_TakingPhoto_Smely);
			this.smelyBtn.add_Click(new EventHandler(this.smelyBtn_Click));
			return this.mBar;
		}
		private void RefreshAppBar()
		{
			if (base.get_ApplicationBar() == null)
			{
				return;
			}
			if (this.nowMode == SnsPostPage.InputMode.NoneMode)
			{
				if (base.get_ApplicationBar().get_Buttons().get_Count() > 1)
				{
					base.get_ApplicationBar().get_Buttons().RemoveAt(0);
					return;
				}
			}
			else
			{
				if (base.get_ApplicationBar().get_Buttons().get_Count() == 1)
				{
					base.get_ApplicationBar().get_Buttons().Insert(0, this.smelyBtn);
				}
				if (this.nowMode == SnsPostPage.InputMode.InputSmileyMode)
				{
					this.smelyBtn.set_Text(strings.Album_TakingPhoto_Text);
					this.smelyBtn.set_IconUri(new Uri("/Resource/Img/Chat/keyboard.png", 2));
					return;
				}
				this.smelyBtn.set_Text(strings.Album_TakingPhoto_Smely);
				this.smelyBtn.set_IconUri(new Uri("/Resource/Img/Chat/expression.png", 2));
			}
		}
		private void smelyBtn_Click(object sender, EventArgs e)
		{
			if (this.isDeleteState)
			{
				this.ResetAllPic();
			}
			if (this.nowMode != SnsPostPage.InputMode.NoneMode && this.nowMode != SnsPostPage.InputMode.InputTxtMode)
			{
				if (this.InputTextBox != null && this.InputTextBox.realBox != null)
				{
					try
					{
						this.InputTextBox.FocusRealBox();
					}
					catch
					{
					}
				}
				return;
			}
			this.SwitchToMode(SnsPostPage.InputMode.InputSmileyMode);
		}
		private void OkMenuBtn_Click(object sender, EventArgs e)
		{
			this.SwitchToMode(SnsPostPage.InputMode.NoneMode);
			this.NetStatusProgressBar.set_Visibility(0);
			CircleMainPage.GotoTop();
			base.get_Dispatcher().BeginInvoke(delegate
			{
				this.DoSendSnsObj();
			});
			this.DoNavigate();
		}
		private void DoNavigate()
		{
			if (this.isFromShareContent)
			{
				base.GoToPage("/Source/Plugin/Sns/Circle/UI/CircleMainPage.xaml", null, true);
				return;
			}
			base.GoBack();
		}
		private void DoSendSnsObj()
		{
			bool flag = false;
			if (this.picPathList.get_Count() == 0)
			{
				flag = true;
			}
			bool flag2 = false;
			bool flag3 = false;
			string text = EmojiManager.GetInstance().ConvertInputStrToCodeStr(this.InputTextBox.Text, ref flag2);
			text = EmojiManager.GetInstance().SbCodeToUtf16Code(text, ref flag3);
			this.InputTextBox.Text = "";
			this.SmileyView.ClearSmileyStack();
			uint syncFlag = 0u;
			if (this.bIfSyncToTencentWeibo)
			{
				syncFlag = SnsPostService.getSyncToBlogFlag(syncFlag);
			}
			if (this.bIfSyncToFB)
			{
				syncFlag = SnsPostService.getSyncToFacebookFlag(syncFlag);
			}
			int privacy = 0;
			if (this.mListSnsGroupId != null && this.mListSnsGroupId.get_Item(0) == 0uL)
			{
				privacy = 1;
				this.mListSnsGroupId = null;
			}
			TloLocation tloLocation = null;
			bool? isChecked = this.LocationToggle.get_IsChecked();
			if (isChecked.GetValueOrDefault() && isChecked.get_HasValue())
			{
				tloLocation = new TloLocation();
				tloLocation.fLatitude = (float)this.mLatitude;
				tloLocation.fLongitude = (float)this.mLongitude;
				tloLocation.strCity = this.mAddress;
			}
			List<string> list = new List<string>();
			if (this.conList != null)
			{
				for (int i = 0; i < this.conList.get_Count(); i++)
				{
					list.Add(this.conList.get_Item(i).strUsrName);
				}
			}
			if (!flag)
			{
				SnsPostService.UploadAndPost(this.picPathList, list, tloLocation, text, syncFlag, privacy, SnsObjectType.MMSNS_OBJECT_PHOTO, BgImgType.MMSNS_SETBGIMG_SELFPIC, this.mListSnsGroupId);
				return;
			}
			SnsPostService.UploadAndPost(null, list, tloLocation, text, syncFlag, privacy, SnsObjectType.MMSNS_OBJECT_TEXT, BgImgType.MMSNS_SETBGIMG_SELFPIC, this.mListSnsGroupId);
		}
		private void InitSmiley()
		{
			this.SmileyView.Click = new SmileyClick(this.SmileyClick);
			this.SmileyView.EmojiClick = new SmileyClick(this.EmojiClick);
		}
		private void SmileyClick(int smiley)
		{
			if (smiley == -1)
			{
				this.SwitchToMode(SnsPostPage.InputMode.NoneMode);
				return;
			}
			if (smiley != -2)
			{
				int selectionStart = this.InputTextBox.realBox.get_SelectionStart();
				string text = this.InputTextBox.Text;
				string text2 = text.Substring(0, selectionStart);
				string smileyText = SmileyManager.GetInstance().getSmileyText(smiley);
				this.SmileyView.PushSmileyStack(smileyText);
				string text3 = text2 + smileyText;
				int length = text3.get_Length();
				text3 += text.Substring(selectionStart);
				this.InputTextBox.Text = text3;
				this.InputTextBox.realBox.set_SelectionStart(length);
				this.InputTextBox.realBox.set_SelectionLength(0);
				return;
			}
			if (this.InputTextBox.realBox.get_SelectionLength() > 0)
			{
				int selectionStart2 = this.InputTextBox.realBox.get_SelectionStart();
				int selectionLength = this.InputTextBox.realBox.get_SelectionLength();
				string text4 = this.InputTextBox.Text;
				string text5 = text4.Substring(0, selectionStart2) + text4.Substring(selectionStart2 + selectionLength);
				this.InputTextBox.Text = text5;
				this.InputTextBox.realBox.set_SelectionStart(selectionStart2);
				this.InputTextBox.realBox.set_SelectionLength(0);
				return;
			}
			int selectionStart3 = this.InputTextBox.realBox.get_SelectionStart();
			string text6 = this.InputTextBox.Text;
			string text7 = text6.Substring(0, selectionStart3);
			string text8 = this.SmileyView.RemoveLastSmiley(text7);
			int num = text7.get_Length() - text8.get_Length();
			text7 = text8 + text6.Substring(selectionStart3);
			this.InputTextBox.Text = text7;
			this.InputTextBox.realBox.set_SelectionStart(selectionStart3 - num);
			this.InputTextBox.realBox.set_SelectionLength(0);
		}
		private void EmojiClick(int emojiIndex)
		{
			int selectionStart = this.InputTextBox.realBox.get_SelectionStart();
			string text = this.InputTextBox.Text;
			string text2 = text.Substring(0, selectionStart);
			string utf16CodeByIndex = EmojiManager.GetInstance().GetUtf16CodeByIndex(emojiIndex);
			this.SmileyView.PushSmileyStack(utf16CodeByIndex);
			string text3 = text2 + utf16CodeByIndex;
			int length = text3.get_Length();
			text3 += text.Substring(selectionStart);
			this.InputTextBox.Text = text3;
			this.InputTextBox.realBox.set_SelectionStart(length);
			this.InputTextBox.realBox.set_SelectionLength(0);
		}
		private void SmileyView_Tap(object sender, GestureEventArgs e)
		{
			this.bTapFromChildren = true;
			this.ResetAllPic();
		}
		private void InputTextBox_GotFocus(object sender, RoutedEventArgs e)
		{
			this.SwitchToMode(SnsPostPage.InputMode.InputTxtMode);
			this.GetTextState();
		}
		private void InputTextBox_LostFocus(object sender, RoutedEventArgs e)
		{
			this.GetTextState();
		}
		private void inputTxt_KeyDown(object sender, KeyEventArgs e)
		{
			this.GetTextState();
		}
		private void GetTextState()
		{
			if (!string.IsNullOrEmpty(this.InputTextBox.Text))
			{
				this.OkMenuBtn.set_IsEnabled(true);
				return;
			}
			if (this.picPathList.get_Count() == 0)
			{
				this.OkMenuBtn.set_IsEnabled(false);
				return;
			}
			this.OkMenuBtn.set_IsEnabled(true);
		}
		private void showProgressCover(string strCoverTitle)
		{
			if (!this.hasCoverInfront)
			{
				ProcessingCover.getProgressBar(this.LayoutRoot, strCoverTitle, null, false, false, null);
				this.hasCoverInfront = true;
			}
		}
		private void hideProgressCover()
		{
			if (this.hasCoverInfront)
			{
				ProcessingCover.releaseProgressBar(this.LayoutRoot);
				this.hasCoverInfront = false;
			}
		}
		private void btnVisibility_Click(object sender, RoutedEventArgs e)
		{
			SetPostVisibilityPage.GotoThisPage(new MMStandardUIEvent(this.visiRangeChanged), this.mListSnsGroupId);
		}
		private void visiRangeChanged(object obj1, object obj2)
		{
			this.mListSnsGroupId = (obj2 as List<ulong>);
			this.txtVisiKind.Text = this.getDisplayVisiText();
			if (this.isSetPrivate())
			{
				this.conList.Clear();
				this.refreshRemindNumber();
				this.ShareToTencentWeiboToggle.set_IsChecked(new bool?(false));
				this.SyncToFBToggle.set_IsChecked(new bool?(false));
			}
		}
		private bool isSetPrivate()
		{
			bool result = false;
			if (this.mListSnsGroupId != null && this.mListSnsGroupId.get_Count() > 0)
			{
				result = (this.mListSnsGroupId.get_Item(0) == 0uL);
			}
			return result;
		}
		private string getDisplayVisiText()
		{
			Size desireSize = ToolFunction.GetDesireSize(this.txtVisiLead);
			this.txtVisiKind.set_MaxWidth(440.0 - (64.0 + desireSize.get_Width()));
			this.txtVisiKind.set_Width(440.0 - (64.0 + desireSize.get_Width()));
			if (this.mListSnsGroupId == null || this.mListSnsGroupId.get_Count() == 0)
			{
				return strings.WC_Commit_SelectGroup_Public;
			}
			if (this.mListSnsGroupId.get_Item(0) == 1uL)
			{
				return strings.WC_Commit_SelectGroup_Friend;
			}
			if (this.mListSnsGroupId.get_Item(0) == 0uL)
			{
				return strings.WC_Commit_SelectGroup_Private;
			}
			if (this.mListSnsGroupId.get_Item(0) >= 6uL)
			{
				string text = "";
				using (List<ulong>.Enumerator enumerator = this.mListSnsGroupId.GetEnumerator())
				{
					while (enumerator.MoveNext())
					{
						ulong current = enumerator.get_Current();
						SnsTagInfo snsTagInfo = StorageMgr.snsTag.method_1(current.ToString("X16"));
						if (snsTagInfo != null && snsTagInfo.strTagID != null)
						{
							if (text.get_Length() > 0)
							{
								text += ",";
							}
							text += snsTagInfo.strTagName;
						}
					}
				}
				return text;
			}
			return "";
		}
		[DebuggerNonUserCode]
		public void InitializeComponent()
		{
			if (this._contentLoaded)
			{
				return;
			}
			this._contentLoaded = true;
			Application.LoadComponent(this, new Uri("/MicroMsg;component/Source/Plugin/Sns/Common/UI/UploadAndPost/SnsPostPage.xaml", 2));
			this.LayoutRoot = (Grid)base.FindName("LayoutRoot");
			this.rootScrollViewer = (ScrollViewer)base.FindName("rootScrollViewer");
			this.LayoutContent = (StackPanel)base.FindName("LayoutContent");
			this.InfoText = (TextBlock)base.FindName("InfoText");
			this.InputTextBox = (ChatInputTextBox)base.FindName("InputTextBox");
			this.ImagePanel = (WrapPanel)base.FindName("ImagePanel");
			this.btnVisibility = (ClickableLayout)base.FindName("btnVisibility");
			this.panelVisibility = (StackPanel)base.FindName("panelVisibility");
			this.imgVisi = (Image)base.FindName("imgVisi");
			this.txtVisiLead = (TextBlock)base.FindName("txtVisiLead");
			this.txtVisiKind = (DynamicTextBlock)base.FindName("txtVisiKind");
			this.btnCommonSetting = (ClickableLayout)base.FindName("btnCommonSetting");
			this.WithPanel = (StackPanel)base.FindName("WithPanel");
			this.WithText = (TextBlock)base.FindName("WithText");
			this.remindNumber = (TextBlock)base.FindName("remindNumber");
			this.LocatonImg = (Image)base.FindName("LocatonImg");
			this.LocatonTxt = (TextBlock)base.FindName("LocatonTxt");
			this.LocationToggle = (ToggleSwitchButton)base.FindName("LocationToggle");
			this.SyncToWeiboGrid = (StackPanel)base.FindName("SyncToWeiboGrid");
			this.SyncToWeiboImg = (Image)base.FindName("SyncToWeiboImg");
			this.SyncToWeiboTxt = (TextBlock)base.FindName("SyncToWeiboTxt");
			this.ShareToTencentWeiboToggle = (ToggleSwitchButton)base.FindName("ShareToTencentWeiboToggle");
			this.SyncToFBGrid = (StackPanel)base.FindName("SyncToFBGrid");
			this.SyncToFBImg = (Image)base.FindName("SyncToFBImg");
			this.SyncToFBTxt = (TextBlock)base.FindName("SyncToFBTxt");
			this.SyncToFBToggle = (ToggleSwitchButton)base.FindName("SyncToFBToggle");
			this.PrivacyImg = (Image)base.FindName("PrivacyImg");
			this.PrivacyTxt = (TextBlock)base.FindName("PrivacyTxt");
			this.PrivacyTipTxt = (TextBlock)base.FindName("PrivacyTipTxt");
			this.SetPrivacyToggle = (ToggleSwitchButton)base.FindName("SetPrivacyToggle");
			this.NetStatusProgressBar = (PerformanceProgressBar)base.FindName("NetStatusProgressBar");
			this.SmileyView = (SmileyOverlay)base.FindName("SmileyView");
		}
	}
}
